package com.markerhub.RabbitMQ;

import com.alibaba.fastjson.JSON;
import com.markerhub.Util.MallUtils;
import com.markerhub.entity.ElasticSearchBlog;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queuesToDeclare = @Queue("UpdateES"))
public class customerElasticSearch {

    @Autowired
    private RestHighLevelClient restHighLevelClient;



    @RabbitHandler
    public void ElasticSearchUpdate(ElasticSearchBlog blog)throws Exception{
        UpdateRequest updateRequest=new UpdateRequest("vueblog",String.valueOf(blog.getId()));
        updateRequest.doc(JSON.toJSONString(blog), XContentType.JSON);
        restHighLevelClient.update(updateRequest, RequestOptions.DEFAULT);

    }
}
